#!/bin/bash
cd ~/app-root/data/github-sh/pkg/firefox/
grep -o "[0-9\.]\{4,7\}esr" ~/app-root/data/temp/firefox/oldesr > pkgver.txt
sed 's#.*\([0-9]\{1,2\}\)$#\1#'  ~/app-root/data/temp/firefox/oldesr >build.txt
if ! grep -q $(cat pkgver.txt)'$' ~/app-root/data/temp/pkg/tmp/firefox-esr-zh-cn/PKGBUILD;then
differ=0
fi
if ! grep -q pkgrel=$(cat build.txt) ~/app-root/data/temp/pkg/tmp/firefox-esr-zh-cn/PKGBUILD;then
differ=0
fi
if [ $differ == "0" ];then
sed -i -e "/pkgver=/c\pkgver=$(cat pkgver.txt)" -e "/pkgrel=/s#[0-9]\{1,2\}#$(cat build.txt)#" -e 's#http:#https:#' ~/app-root/data/temp/pkg/firefox-esr-zh-cn/PKGBUILD
sed -i -e "s#[0-9\.]\{4,7\}esr#$(cat pkgver.txt)#g" -e "/pkgrel/s#[0-9]\{1,2\}#$(cat build.txt)#" -e "s#build[0-9]\{1,2\}#build$(cat build.txt)#" ~/app-root/data/temp/pkg/firefox-esr-zh-cn/.SRCINFO
fi
rm -f *.txt
cd ~/app-root/data/temp/pkg/
diff -q firefox-esr-zh-cn/ tmp/firefox-esr-zh-cn/ | sed -e 's#Files ##' -e 's#and.*differ##' >diff.txt
zip pkg.zip -r $(cat diff.txt)
rm -rf firefox-esr-zh-cn/ ~/app-root/data/github-sh/pkg/firefox/*.txt
